<?php
$page_fixed = new Page_Fixed('contact');
$contact_value = json_decode(base64_decode($page_fixed->result['con_value']),1);

$bg_errorMsg = '';
$bg_success = '';
$action = getValue('action','str','POST','');
if($action == 'execute'){
   $captcha = getValue('captcha','str','POST','');
   if($captcha == $_SESSION["securitycode"]) {
      $con_name = getValue('con_name','str','POST','',2);
      $con_email = getValue('con_email','str','POST','',2);
      if(!filter_var($con_email, FILTER_VALIDATE_EMAIL)){
        $bg_errorMsg .= 'Email không đúng định dạng <br>';
      }
      $con_subject = getValue('con_subject','str','POST','',2);
      $con_detail = getValue('con_detail','str','POST','',2);
      $con_date = time();
      $myform = new generate_form();
      $myform->add('con_name','con_name',0,1,'',1,'Bạn chưa nhập tên');
      $myform->add('con_email','con_email',0,1,'',1,'Bạn chưa nhập email');
      $myform->add('con_subject','con_subject',0,1,'',1,'Bạn chưa nhập tiêu đề');
      $myform->add('con_detail','con_detail',0,1,'',1,'Bạn chưa nhập nội dung');
      $myform->add('con_date','con_date',1,1,0);
      $myform->addTable('contact');
      $bg_errorMsg .= $myform->checkdata();
      if($bg_errorMsg == ''){
        $db = new db_execute($myform->generate_insert_SQL());
        $bg_success = 1;
      }
   }else {
     $bg_errorMsg .= 'Mã xác nhận không đúng !<br>';        
   }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi-VN" lang="vi-VN" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link href="<?=DOMAIN?>/favicon.ico" type="image/x-icon" rel="shortcut icon"/>
   <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
   <?php
   echo $page_fixed->Seo();
   ?>
   <!-- css -->
   <link rel="stylesheet" type="text/css" href="/themes/css/base.css"/>
   <link rel="stylesheet" type="text/css" href="/themes/css/style.css"/>
   <link rel="stylesheet" type="text/css" href="/themes/css/contact.css"/>

   <!-- js -->
   <script type="text/javascript" src="/themes/js/jquery-1.9.0.min.js"></script>
   <script type="text/javascript" src="/themes/js/common.js"></script>
   <?=$facebook_script?>
</head>
<body>
   <div class="wrap">
      <?php include 'view/common/vcom_header.php';?>
      <div class="breadcrumb">
         <span itemtype="http://data-vocabulary.org/Breadcrumb" itemscope="itemscope" class="crumb_item">
            <a itemprop="url" rel="up" class="crumb" href="/"><span itemprop="title">Trang chủ</span></a>
            <span class="arrow"><img src="/themes/img/navRow.png" alt="bredcrumb arrow"></span>
         </span>
         <span itemtype="http://data-vocabulary.org/Breadcrumb" itemscope="itemscope" class="crumb_item">
            <a itemprop="url" rel="up" class="crumb" href="/lien-he/"><span itemprop="title">Liên hệ</span></a>
            <span class="arrow"><img src="/themes/img/navRow.png" alt="bredcrumb arrow"></span>
         </span>
      </div>
      <div class="primary">
         <?php include 'view/common/vcom_sidebar.php';?>
         <div class="content">
            <div class="contact">
               <div class="contact_info">
                  <?=$contact_value['content']?>
               </div>
               <div class="contact_map">
                  <!--<img alt="Bản đồ" src="http://maps.googleapis.com/maps/api/staticmap?center=<?=$contact_value['address']?>&zoom=16&size=400x300&sensor=true&markers=size:mid%7Ccolor:red%7C<?=$contact_value['address']?>"/>-->
                  <img alt="Bản đồ chỉ đường đến Daejung Việt Nam" src="/themes/img/ban-do-daejung-viet-nam.jpg" style="width: 400px; height: 300px;"/>
               </div>
               <div class="contact_form" id="contact_form">
                  <h2 class="color_site">Liên hệ theo mẫu</h2>
                  <form class="form_contact" action="#contact_form" method="POST" onsubmit="return validSend();">
                  <?=($bg_errorMsg ? '<div class="alert">'.$bg_errorMsg.'</div>' : '')?>
                  <?=($bg_success ? '<div class="alert alert-success">'.'Cảm ơn bạn đã gửi liên hệ. Chúng tôi sẽ liên lạc với bạn trong thời gian sớm nhất!'.'</div>' : '')?>
                     <input type="text" value="" placeholder="Họ tên của bạn" class="con_name" name="con_name"/><br />
                     <input type="text" value="" placeholder="Email của bạn" class="con_email" name="con_email"/><br />
                     <input type="text" value="" placeholder="Tiêu đề liên hệ" class="con_subject" name="con_subject"/><br />
                     <textarea placeholder="Nội dung liên hệ" class="con_detail" name="con_detail"></textarea><br />
                     <img src="/home/securitycode.php" id="myimg" /><br />
                     <input class="form-control captcha" type="text" name="captcha" value="" placeholder="Mã xác nhận" /><br />
                     <input type="submit" class="btn btn-contact" id="btn-contact" value="Gửi đi" name="" />  
                     <input type="hidden" name="action" value="execute"/>  
                  </form>
                  <script>
                     function isemail(email) {
                     	var re = /^(\w|[^_]\.[^_]|[\-])+(([^_])(\@){1}([^_]))(([a-z]|[\d]|[_]|[\-])+|([^_]\.[^_])*)+\.[a-z]{2,3}$/i
                     	return re.test(email);
                     }
                     function validSend(){	
                     	if($('.con_name').val()==''){
                     		alert('Hãy nhập tên của bạn');
                     		$('.con_name').focus();
                           return false;
                     	}
                        if($('.con_email').val()==''){
                     		alert('Hãy nhập con_email');
                           $('.email').focus();
                     		return false;
                     	}
                     	if($('.con_subject').val()==''){
                     		alert('Hãy nhập tiêu đề liên hệ.');
                     		$('.con_subject').focus();
                           return false;
                     	}
                        if($('.con_detail').val()==''){
                     		alert('Hãy nhập nội dung');
                     		$('.con_detail').focus();
                           return false;
                     	}   
                     	if(!isemail($('.con_email').val())){
                     		alert('Hãy nhập 1 Email hợp lệ.');
                     		$('.con_email').focus();
                           return false;
                     	}
                        if($('.captcha').val()==''){
                     		alert('Hãy nhập mã xác nhận');
                     		$('.captcha').focus();
                           return false;
                     	}
                     }
                  </script>
               </div>
            </div>
         </div>
      </div>
      <?php include 'view/common/vcom_footer.php';?>
   </div>
</body>
</html>